package com.anycl.design.structural.composite;

import java.util.ArrayList;

/**
 * 复合组件构建类，模拟某个组织部门
 */
public class Composite extends Component {
    public Composite(String name) {
        super(name);
    }

    public ArrayList<Component> componentArrayList = new ArrayList<>();

    @Override
    public void add(Component component) {
        this.componentArrayList.add(component);
    }

    @Override
    public void remove(Component component) {
        this.componentArrayList.remove(component);
    }

    @Override
    public void display(int depth) {
        for (int i = 0; i < depth; i++) {
            System.out.print("*");
        }
        System.out.println(getName());
        for (Component component : componentArrayList) {
            component.display(depth + 1);
        }
    }
}
